#!/bin/sh
OCFTDIR=/usr/share/resource-agents/ocft
CONFDIR=$OCFTDIR/configs

prereq_run() {
	eval "$@"
}
prereq_prog() {
	which $@
}

test_prereq() {
	local tp arg
	tp=`echo $prereq|sed 's/:.*//'`
	arg=`echo $prereq|sed 's/[a-z]*://'`
	prereq_$tp $arg >/dev/null 2>&1
}

rm -f ocft.FAILED
rc=0
while read f prereq; do
	if [ -n "$prereq" ] && ! test_prereq; then
		echo "$f: prerequisite not fulfilled, skipping"
		continue
	fi
	ocft make $f
	if ! ocft test $f; then
		echo $f >> ocft.FAILED
		rc=1
	fi
done < $OCFTDIR/runocft.prereq

if [ -f ocft.FAILED ]; then
	echo "The following ocft tests failed:"
	cat ocft.FAILED
fi

exit $rc
